CC = gcc
CFLAGS = -Werror -Wall -g
BUILD_DIR = ./build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
LIB_DIR = ./lib
TEST_DIR = ./test

# =======================================================
_LIBOBJ = stdio.o string.o
LIBOBJ = $(patsubst %,$(OBJ_DIR)/%, $(_LIBOBJ))

_TESTOBJ = strlen_test.o rand_test.o strcmp_test.o strcpy_test.o sprintf_test.o
TESTOBJ = $(patsubst %,$(OBJ_DIR)/%, $(_TESTOBJ))

OBJ = $(LIBOBJ) $(TESTOBJ)

$(OBJ_DIR)/%.o: $(LIB_DIR)/%.c
	@$(CC) $(CFLAGS) -c $^ -o $@

$(OBJ_DIR)/%.o: $(TEST_DIR)/%.c
	@$(CC) $(CFLAGS) -c $^ -o $@
# =======================================================

run: $(OBJ)
	@$(CC) $(CFLAGS) $(OBJ_DIR)/$(TARGET)_test.o $(LIBOBJ) -o $(BIN_DIR)/$(TARGET)_test
	@$(BIN_DIR)/$(TARGET)_test

gdb: $(OBJ)
	@$(CC) $(CFLAGS) $(OBJ_DIR)/$(TARGET)_test.o $(LIBOBJ) -o $(BIN_DIR)/$(TARGET)_test
	@gdb $(BIN_DIR)/$(TARGET)_test

git:
	@git add .
	@git commit

clean:
	rm -rf $(OBJ_DIR)/* $(BIN_DIR)/*
